<?php
/**
 * Created by PhpStorm.
 * User: lg
 * Date: 2017/12/8
 * Time: 14:00
 */

namespace app\master\controller;

use app\common\rbac\Auth;

class System extends Base
{

    public function banner()
    {
        return $this->fetch();
    }

    public function bannerlist()
    {
        $page['page'] = input("page");
        $page['limit'] = input("limit");
        $result['data'] = db('banner')
            ->page($page['page'], $page['limit'])
            ->select();
        foreach ($result['data'] as $k=>$v){
            $result['data'][$k]['goods_name']=db('goods')->where(['goods_id'=>$result['data'][$k]['goods_id']])->value('goods_name');
        }
        $result['count'] = db('banner')->count();
        return $this->_table_return(0, "", $result['count'], $result['data']);
    }
    public function changebanner()
    {
        $id=input('id');
        db('banner')->where(['banner_id'=>$id])->delete();
        return $this->_ajax_return(200,'删除成功','banner');
    }
    public function addbanner()
    {
        if(request()->isPost()){
            $data['goods_id']=input('goods_id');
            $data['path']=input('path');
            db('banner')->insert($data);
            return $this->_ajax_return(200,'添加成功','banner');
        }
        $goods=db('goods')->where(['isdelete'=>0,'status'=>1])->select();
//        var_dump($goods);
        $this->assign('goods',$goods);
        return $this->fetch();
    }
    public function editbanner()
    {
        $id=input('id');
        if(request()->isPost()){
            $data['goods_id']=input('goods_id');
            $data['path']=input('path');
            db('banner')->where(['banner_id'=>$id])->update($data);
            return $this->_ajax_return(200,'修改成功','banner');
        }

        $info=db('banner')->where(['banner_id'=>$id])->find();
        $goods=db('goods')->where(['isdelete'=>0,'status'=>1])->select();
//        var_dump($goods);
        $this->assign('goods',$goods);
        $this->assign('info',$info);
        return $this->fetch();
    }
    public function auth()
    {
        $auth = $this->rbac();
        $permession = $auth->getPermession();
        dump($permession);
    }
}